<!DOCTYPE html>
<html lang="en">
    <head>

        <meta charset="UTF-8">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <title>登录页</title>
        <meta name="viewport" content="width=device-width,initial-scale=1">
        <link rel="stylesheet" type="text/css" href="normalize.css">
        <link rel="stylesheet" type="text/css" href="login.css">
    </head>
    <body>
        <header>
            <h1>登录</h1>
        </header>
        <section>
            <form id="form_one" class="login_form">
                <input class="telePhone_num" id="username" name="username" type="text" placeholder="输入手机号获取验证码">
                <br/>
                <img class="phone_pic" src="phone.png" alt="phone">
                <input class="verify_num" id="verify" name="verify" type="text" placeholder="验证码" >
                <input class="get_verify_num" id='getVerify' type="button" value="获取验证码">
                <br/>
                <img class="message_pic" src="message.png" alt="message">
                <input class="login_btn"  type="button" value="登录">
            </form>
        </section>
        <img class="bear_hand1" src="hand.png" alt="bear_body">
        <img class="bear_body" src="bearbody.png" alt="bear_body">
        <img class="bear_hand2" src="hand.png" alt="bear_body">
        <br/>
        <script src="picturefill.js"></script>
        <script src="vendor/jquery-1.10.0.js"></script>
        <script src="vendor/jquery.validate-1.13.1.js"></script>
        <script src="layer.js"></script>
        <script src="vendor/additional-methods.js"></script>
        <script src="../public/version_number.js"></script>
        <script type="text/javascript">


            //验证码发送
            var wait=30;
            function time(o){
                if (wait==0) {
                    o.removeAttribute("disabled");
                    o.value="输入验证码";
                    o.style.backgroundColor="#fe9900";
                    wait=30;
                }else{
                    o.setAttribute("disabled", true);
                    o.value=wait+"秒后重新获取";
                    o.style.backgroundColor="#8f8b8b";
                    wait--;
                    setTimeout(function(){
                        time(o)
                    },1000)
                }
            };
            $(".get_verify_num").click(function(){
                var phone =$("#username").val();
                if(phone==""){
                    layer.msg("请输入电话号码");
                    return false;
                }
                else if (!/^0?(13|14|15|17|18)[0-9]{9}$/i.test(phone)){
                    layer.msg("请输入正确的手机号码");
                    return false;
                }else{
                    $("#span").hide();
                    time(this);
                }
                $.ajax({
                    url:"https://newapp.icandrive.cn/api/code.php",
                    data:{phone:phone},
                    dataType:'json',
                    type:'post',
                    success:function(data){
                        if(data.status){
                            layer.msg("短信发送成功");
                        }else{
                            // layer.msg('系统维护中',function(){
                            //     history.go(0)
                            // },1000);
                        }
                    },
                    error: function () {
                        layer.msg('系统维护中');
                    }
                });
            });

            $(".login_btn").click(function(){
                var verify =$(".verify_num").val();
                var  phone = $(".telePhone_num").val();
                if(verify==""){
                    layer.msg("验证码不能为空");

                    return false;
                }else{
                    $("#span").hide();
                }
                $.ajax({
                    url:"https://newapp.icandrive.cn/api/login.php/login.php",
                    type:'post',
                    dataType:'json',
                    data:{phone:phone,code:verify},
                    success:function (data) {
                        if(data.status==400){
                            layer.msg(data.msg);
                        }
                        if(data.status==401){
                            layer.msg(data.msg);
                        }
                        if(data.status==199){
                            window.location.href="../startpage/stratpage.html";
                        }
                        if(data.status==200){
                            console.log(data.token);
                            // return false;
                            localStorage.setItem('savalogintooken', data.token);
                            localStorage.phone=data.token;

                            if(data.role_id==1){
                                localStorage.setItem('savestudentstatus', 1);
                                localStorage.role_id_te=1;
                                window.location.href="../index/index.html";
                            }
                            if(data.role_id==2){
                                localStorage.setItem('savestudentstatus', 2);
                                localStorage.role_id_st=2; window.location.href="../order/oder.html";
                            }
                        }
                    },
                    error:function () {
                        layer.msg('系统繁忙');
                    }
                });
            });




        </script>

        <script>
            document.addEventListener("plusready", function() {
                // 注册返回按键事件
                plus.key.addEventListener('backbutton', function() {
                    // 事件处理
                    plus.nativeUI.confirm("退出程序？", function(event) {
                        if (event.index) {
                            plus.runtime.quit();
                        }
                    }, null, ["取消", "确定"]);
                }, false);
            });

        </script>
    </body>
</html>
